<template>
	<view class="login">
		<form action="" method="get">
			<input class="iphoneNumber" type="text" placeholder="请输入手机" v-model="phone">
			<input class="send" type="button" value="发送验证码" @click="send()">
			<view style="clear: both;"></view>
			<input  class="code" type="text" placeholder="请输入邮箱" v-model="mail">
			<input  class="code" type="text" placeholder="请输入验证码" v-model="code">
		</form>
			<input class="sendCode" type="button" value="登陆" @click="sendcode()">
		<view></view>
	</view>
</template>

<script>
	export default{
		name:'login',
		components:{
		},
		data(){
			return{
				phone:'',
				code:'',
				mail:''
			}
		},
		methods:{
			send(){
				if(this.phone.length != 11)
					wx.showToast({
						title: '手机号有误',
						duration: 2000//持续的时间
					})
				else if(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/).test(this.mail))
					wx.showToast({
						title: '请输入正确的邮箱',
						duration: 2000//持续的时间
					})
				else uni.request({
						url:"http://" + getApp().globalData.IpAddr + "/user/code",
						method:"POST",
						data:{'phone':this.phone , 'code':this.code , 'password':"" , "email":this.mail},
						success:res => {
							wx.showToast({
							     title: '验证码已发送',
							     duration: 2000//持续的时间
							   })
							   // console.log(res)
						}
					})
			},
			sendcode(){
				uni.request({
						url:"http://" + getApp().globalData.IpAddr + "/user/login",
						method:"POST",
						data:{'phone':this.phone , 'code':this.code , 'password':"" , "email":this.mail},
						success:res => {
							console.log(res)
							// wx.showToast({	title: res.data.data,	duration: 2000	})
							if (!res.data.success) {
								wx.showToast({	title: res.data.errorMsg,	duration: 2000	})
							}else {
								getApp().globalData.token = res.data.data
								uni.reLaunch({	url:"/pages/index/index",	})
							}
						}
					})
					
			}
			
		}
	}
</script>

<style>
	.login{
		width: 100vw;
		height: 100vh;
		background-color: #f7f5f5;
		padding: 3vw;
	}
	.iphoneNumber{
		background-color: #ffffff;
		border-radius: 5px;
		width: 45vw;
		float: left;
		color: #c4c4cc;
		padding: 3vw;
	}
	.send{
		background-color: #27c21c;
		border-radius: 5px;
		width: 25vw;
		padding: 3vw;
		float: left;
		margin-left: 5vw;
		color: white;
		text-align: center;
	}
	.code{
		background-color: #ffffff;
		border-radius: 5px;
		width: 90vw;
		color: #c4c4cc;
		padding: 10px;
		margin-top: 10px;
	}
	.sendCode{
		background-color: #27c21c;
		border-radius: 5px;
		width: 70vw;
		padding: 3vw;
		float: left;
		margin-left: 5vw;
		color: white;
		text-align: center;
	}
</style>